function ecogChannelPlot(X,Y,dat,Anat,param)
% ecogDiscPlot(X,Y,dat,Anat,param)
% plots discs on recon image
% INPUT: X,Y vectors of coordinates coregistered to the image Anat (use ginput)
%        Anat: the image (use imread)
%        dat: the data to visualize. 
%        param: struct holding parameter fields (optional)
%              range: two element interval 
%              maxradius: maximum disc radius in pixel (fitted to Anat)
%              style: fill and edge color
%        points: number of points to draw a circle


if nargin <5,
    param=struct;
end
absdat = abs(dat);
styleColorIdx = double(dat<0)+1; %1 if positive, 2 if negative

if ~isfield(param,'range'),
    param.range = [min(absdat), max(absdat)];
end
if ~isfield(param,'maxradius'),
    param.maxradius = 24;
end
if ~isfield(param,'style'),
    param.style = [1 0 0; 0 0 1]; % positive red, negative blue
end
if ~isfield(param,'points'),
    param.points = 36;
end
if ~isfield(param,'ignorechannels'),
    param.ignorechannels = [];
end

imshow(Anat);
hold on;
for ch=1:length(dat),
    if isempty(intersect(ch,param.ignorechannels)),
        radius = (1+((max([absdat(ch),param.range(1)])-param.range(1))/diff(param.range))*param.maxradius);
        H=drawfilledcircle([X(ch),Y(ch)],radius,param.points,param.style(styleColorIdx(ch),:));
    end
end


function H=drawfilledcircle(center,radius,NOP,style)
%---------------------------------------------------------------------------------------------
% H=CIRCLE(CENTER,RADIUS,NOP,STYLE)
% This routine draws a circle with center defined as
% a vector CENTER, radius as a scaler RADIS. NOP is 
% the number of points on the circle. As to STYLE,
% use it the same way as you use the rountine PLOT.
% Since the handle of the object is returned, you
% use routine SET to get the best result.
%
%   Usage Examples,
%
%   circle([1,3],3,1000,':'); 
%   circle([2,4],2,1000,'--');
%
%   Zhenhai Wang <zhenhai@ieee.org>
%   Version 1.00
%   December, 2002
%---------------------------------------------------------------------------------------------

if (nargin <3),
 error('Please see help for INPUT DATA.');
elseif (nargin==3)
    style='y';
end;
THETA=linspace(0,2*pi,NOP);
RHO=ones(1,NOP)*radius;
[X,Y] = pol2cart(THETA,RHO);
X=X+center(1);
Y=Y+center(2);
H=fill(X,Y,style);
set(H,'edgecolor',style);